import Cookies from 'js-cookie'

const user = {
  state: {
    token: Cookies.get('token'),
    userName: '',
    nikeName: '',
    menu: {}
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token
    },
    SET_USERNAME(state, userName) {
      state.user = user
    },
    SET_NIKENAME(state, nikeName) {
      state.name = name
    },
    SET_MENU(state, menu) {
      state.menu = menu
    },
    GET_MENU(state) {
      return state.menu
    },
    REMOVE_TOKEN(state) {
      Cookies.remove('token')
      state.token = Cookies.get('token')
      state.userName = ''
      state.nikeName = ''
      state.menu = {}
    }
  },
  actions: {
    set_user({commit}, val) {
      commit('SET_TOKEN', val.token)
      commit('SET_USERNAME', val.data.userName)
      commit('SET_NIKENAME', val.data.nikeName)
      commit('SET_MENU', val.data.groupId)
      Cookies.set('token', val.token)
    }
  }
}

export default user
